<%--
  Created by IntelliJ IDEA.
  User: 0xdF
  Date: 2022/11/9
  Time: 10:04
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<link rel="stylesheet" href="./css/layui.css">
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<head>
    <title>注册</title>
</head>
<%@ include file="./head.jsp"%>
<body>
<div  style="margin: 20px 100px">
    <form action="./reg.do" method="post" >
        <br>
        <label class="layui-form-label" style="font-weight: bolder;font-size: 20px">用户注册</label>
        <div class="layui-form-item">
            <label class="layui-form-label">账号</label>
            <div class="layui-input-inline">
                <input type="text" name="username" lay-verify="title" autocomplete="off" placeholder="请输入账号" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-inline">
                <input type="password" name="password" lay-verify="title" autocomplete="off" placeholder="请输入密码" class="layui-input">
            </div>
        </div>
        <div style="display: inline-block">
            <input type="button" class="layui-btn layui-btn-danger" value="注册" style="margin-left: 150px" onclick="goReg()">
            <input type="reset" class="layui-btn layui-btn-normal" value="重置" style="">
        </div>
    </form>

</div>
</body>

<script>
    function goReg(){
        let username  = $("input[name='username']").val();
        let password = $("input[name='password']").val();
        if(username === "") {
            alert("用户名为空！")
        }else if(password === ""){
            alert("密码为空！")
        }
        $.post('./regCheck.do',{"username":username},function (res){
            if(res === "500"){
                alert("用户名已经存在！")
            }else{
                $.post('./reg.do',{"username":username,"password":password},function (res){
                    if(res === "200") {
                        alert("注册成功！")
                    }else{
                        alert("注册失败！")
                    }
                })

            }
        });
    }
</script>
</html>
